{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3bf6bba3-cea5-4e28-8e57-bddef9c80013",
   "metadata": {},
   "outputs": [],
   "source": [
    "# imports\n",
    "\n",
    "import os\n",
    "import requests\n",
    "from dotenv import load_dotenv\n",
    "from bs4 import BeautifulSoup\n",
    "from IPython.display import Markdown, display\n",
    "from openai import OpenAI\n",
    "\n",
    "\n",
    "# If you get an error running this cell, then please head over to the troubleshooting notebook!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "62f20a01-2d4f-45ac-a890-fce46d552301",
   "metadata": {},
   "outputs": [],
   "source": [
    "load_dotenv(override=True)\n",
    "api_key = os.getenv('OPENAI_API_KEY')\n",
    "\n",
    "if not api_key:\n",
    "    print('No Api Key was found')\n",
    "elif not api_key.startswith('sk-proj-'):\n",
    "    print(\"An api key was found, but it doesnt start with sk-proj\")\n",
    "elif api_key.strip() != api_key:\n",
    "    print(\"An api key was found, but it might have space in the first or end\")\n",
    "else:\n",
    "    print(\"Api key found and looks good so far!\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f9a1fea0-f228-4310-8c0c-2074cd09ab53",
   "metadata": {},
   "outputs": [],
   "source": [
    "openai = OpenAI()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9db0ddcd-befd-445b-817b-d30c50de9206",
   "metadata": {},
   "outputs": [],
   "source": [
    "message = \"Hello GPT, this is my first message\"\n",
    "response = openai.chat.completions.create(model=\"gpt-4o-mini\", messages=[{\"role\": \"user\", \"content\":message}])\n",
    "print(response.choices[0].message.content)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "00743dac-0e70-45b7-879a-d7293a6f68a6",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Step 1: Create your prompts\n",
    "\n",
    "system_prompt = \"You are a personal tennis coach who helps children learn how to play. \\\n",
    "Write a short summary of advice for a child who is just starting to get interested in tennis. \\\n",
    "Respond in Markdown\"\n",
    "user_prompt = \"\"\"\n",
    "    Even if you’ve both geared up and warmed up, you still need to know all the tennis basics before you step onto the court and play. You can use any combination of tennis grips (like the Semi-Western or Continental grip) and moves like drop shots, lobs, backhand volleys, or forehand strokes to try and win each point. However, learning all the fundamentals of tennis is imperative to play your best tennis:\n",
    "Keep it inside the lines. For singles tennis, the serve must always land over the net, and within the opponent’s opposite service box (the box on either side of the center mark at the service line, also known as the “T”). If the ball hits the net and still lands in the proper service box, it’s called a “let,” and the server gets to start over from the first serve again. Even if the ball technically lands outside the box, as long as any part of it still touches the line, it is still in-play. During a rally, the ball must stay within the singles court boundaries, which are the inner sidelines. For doubles tennis, the outer alleys are in-play. However, most beginner players won’t have a line judge present, so they must call the ball out or raise their finger if the ball lands outside the lines.\n",
    "Keep score. Tennis has a unique scoring system, and it’s important to keep track of your points to determine who will win (and which side you should be serving from). The server always says their score first, even if it is lower than their opponent’s. For example, if the server loses the first three points in a row, the score is love-40.\n",
    "Avoid touching the net. You can rush the net and perform any volleying maneuver you like. However, if any part of you or your racket physically touches the net at any time during a point, you automatically lose. The net is the equal divider between both sides, and any alteration to its positioning, even accidental, is not allowed.\n",
    "Hold onto your racket. Your racket must stay in your hands at all times. If you drop or throw the racket at the ball, you will lose the point. You can only return the ball with your racket and no other part of your body. However, the ball doesn’t necessarily have to touch the racket face—it’s still in-play even if it hits the handle or triangle as well.\n",
    "Hit the ball after one bounce. Once the ball bounces twice, the point is over. Similarly, you can only hit the ball once as well. Even if you clip the ball and it lands in front of you again, the point is over if the ball doesn’t reach your opponent’s side.\n",
    "A ball in the air is a ball in play. Even if your opponent is well behind the baseline in “out” territory, if they make contact with the ball or it hits a part of their body before the bounce, it’s still in-play. A ball can’t be called until it bounces.\n",
    "Win by two. Both games and points must be won by two in a tennis match. In the event of a tie, where both players each win six games in a set resulting in a score of 6-6, a tiebreak is introduced. This is where players must face off in a seven-point mini-match. The players switch sides after each serve point, and the end of the court when the sum of the points equals six or multiples thereof. The first player to reach seven points (leading by two) wins. If the tiebreaker occurs in the last set, the points are instead played first to 10, and the winning player must still win by two points.\n",
    "\"\"\"\n",
    "\n",
    "# Step 2: Make the messages list\n",
    "\n",
    "messages = [\n",
    "    {\"role\": \"system\", \"content\": system_prompt},\n",
    "    {\"role\": \"user\", \"content\": user_prompt}\n",
    "] # fill this in\n",
    "\n",
    "# Step 3: Call OpenAI\n",
    "\n",
    "response =openai.chat.completions.create(\n",
    "    model=\"gpt-4o-mini\",\n",
    "    messages=messages\n",
    ")\n",
    "\n",
    "# Step 4: print the result\n",
    "\n",
    "print(response.choices[0].message.content)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
